//index.js
//获取应用实例
const app = getApp()
const Pager = require('components/aotoo/core')
let mkModal = require('components/modules/modal')

const cpData = require('../cp/data')

const normalData = [
  {
    title: [{title: '色值', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {title: '主题', itemClass: 'item ptb-default mt40 d-bg-primary'},
      {title: '链接', itemClass: 'item ptb-default mt40 d-bg-hover'},
      {title: '辅助', itemClass: 'item ptb-default mt40 d-bg-aux-success'},
      {title: '辅助', itemClass: 'item ptb-default mt40 d-bg-aux-warning'},
      {title: '辅助', itemClass: 'item ptb-default mt40 d-bg-aux-fail'},

      {title: '标题', itemClass: 'item ptb-default mt40 d-bg-text-title'},
      {title: '默认', itemClass: 'item ptb-default mt40 d-bg-text'},
      {title: '备注', itemClass: 'item ptb-default mt40 d-bg-text-info'},
      {title: 'placeholder', itemClass: 'item ptb-default mt40 d-bg-text-placeholder'},
      {title: '禁止', itemClass: 'item ptb-default mt40 d-bg-text-disabled'},
      {title: '背景', itemClass: 'item ptb-default mt40 d-bg-bg'},
    ],
    bodyClass: 'size-sm color-fff d-body-flex'
  },
  {
    title: [{title: '字体', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {title: [{title: '中文', itemClass: 'size'}, {title: ' ', itemClass: 'bb-default'}, {title: '平方', itemClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '数字', itemClass: 'size'}, {title: ' ', itemClass: 'bb-default'}, {title: 'Helvetica', itemClass: 'desc'}], titleClass: 'd-row'}
    ]
  },
  {
    title: [{title: '字号', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {title: [{title: '大标题', itemClass: 'size-title-lg'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '40'}, {title: ' (28)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '认标题', itemClass: 'size-title'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '36'}, {title: ' (25)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '小标题', itemClass: 'size-title-sm'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '32'}, {title: ' (22)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '正文内容', itemClass: 'size'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '30'}, {title: ' (21)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '区域性/表单文字', itemClass: 'size-form'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '28'}, {title: ' (20)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '提示性文字', itemClass: 'size-sm'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '24'}, {title: ' (17)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
      {title: [{title: '标签文字', itemClass: 'size-tag'}, {title: ' ', itemClass: 'bb-default'}, {title: [{title: '22'}, {title: ' (16)', itemClass: 'size-sm color-info'}], titleClass: 'desc'}], titleClass: 'd-row'},
    ]
  },
  {
    title: [{title: '按钮', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {
        title: [
          {title: '提交带load', 'hover-class': 'active', itemClass: 'ui-item ss-button btn-default', aim: 'onSubmit'},
          {title: '禁止', 'hover-class': 'active',itemClass: 'ui-item ss-button disabled btn-grey'},
        ],
        titleClass: 'row-between-flex',
      },
      {title: '大按钮', 'hover-class': 'active',itemClass: 'ss-button larger btn-default mt40'},
      {title: '默认', 'hover-class': 'active',itemClass: 'ss-button btn-default mt40'},
      {title: '小按钮', 'hover-class': 'active',itemClass: 'ss-button small btn-default mt40'},
      {
        title: [
          {title: '固定', 'hover-class': 'active',itemClass: 'ui-item ss-button btn-wid-1 btn-default'},
          {title: '固定', 'hover-class': 'active',itemClass: 'ui-item ss-button btn-wid-2 btn-default'},
          {title: '小按钮', 'hover-class': 'active',itemClass: 'ui-item ss-button small btn-default'},
        ],
        titleClass: 'row-between-flex',
        itemClass: 'mt40'
      },
      {title: '空心', 'hover-class': 'active',itemClass: 'ss-button btn-grey mt40'},
      {title: '空心', 'hover-class': 'active',itemClass: 'ss-button plain btn-grey mt40'},
    ]
  },
  {
    title: [{title: '标签', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {title: 'default', itemClass: 'ss-tag i-block tag-default mr-default'},
      {title: 'waring', itemClass: 'ss-tag i-block tag-waring mr-default'},
      {title: 'fail', itemClass: 'ss-tag i-block tag-fail mr-default'},
      {title: 'primary', itemClass: 'ss-tag i-block tag-primary mr-default'},
      {title: '空心标签', itemClass: 'ss-tag i-block plain tag-fail mr-default'},
      {title: '', itemClass: 'ss-xxxx'},
    ],
    bodyClass: 'ss-center'
  },
  {
    title: [{title: '提示', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {title: '提示性信息展示', itemClass: 'ss-tag tag-fail larger icon-after-toggle flex-row-between-center'},
      {title: [{title: ' ', itemClass: 'icon-question'}, {title: ' 为支持环保，平台默认使用电子合同，不再签署纸质合同'}],titleClass: 'ss-tag tag-fail larger flex-row-wrap', itemClass: 'mt40'},
    ]
  },
  {
    title: [{title: '投影', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {
        title: [
          {title: '上投影(常规)', itemClass: 'ui-item display-card box-shadow-top'},
          {title: '下投影(常规)', itemClass: 'ui-item display-card box-shadow-bottom'},
        ],
        titleClass: 'row-between-flex',
      },
      {title: '小卡片投影', itemClass: 'display-card mt40 box-shadow'},
      {title: '大卡片投影', itemClass: 'display-card mt40 box-shadow'},
    ]
  },
  {
    title: [{title: '定位滚动条', itemClass: 'size-title-lg p-title-line'}],
    '@list': {
      data: [
        {title: '推荐', itemClass: 'item-title active'},
        {title: '标签二', itemClass: 'item-title'},
        {title: '标签三', itemClass: 'item-title'},
        {title: '标签四', itemClass: 'item-title'},
      ],
      itemMethod: {
        aim(e, params, inst) {
          inst.siblings().removeClass('active')
          inst.addClass('active')
        }
      },
      listClass: 'list-tabs',
      // itemClass: 'item-title'
    }
  },
  {
    title: [{title: '结果反馈/加载提示/提示', itemClass: 'size-title-lg p-title-line'}],
    body: [
      {
        title: [
          {title: '反馈', itemClass: 'ui-item ss-button btn-default', aim: 'onClick?type=1'},
          {title: '加载', itemClass: 'ui-item ss-button btn-default', aim: 'onClick?type=2'},
          {title: '提示', itemClass: 'ui-item ss-button btn-default', aim: 'onClick?type=3'},
        ],
        titleClass: 'row-between-flex',
      },
    ]
  },
  {
    title: [{title: '更多组件', itemClass: 'size-title-lg p-title-line'}],
    body: cpData,
  }
]

Pager({
  data: {
    menus: {
      $$id: 'menus',
      data: normalData,
      listClass: 'demo',
      itemClass: 'demo-item',
      type: {
        is: 'scroll',
        'scroll-y': true,
        'enable-back-to-top': true,
      },
      header: {
        $$id: 'toast1'
      }
    },
    navbarLevel2: Pager.item({}),
  },
  levelFixed: false,
  $navbarLevel2: null, 
  viewPortHeight: 0,
  onSubmit(e, p , inst) {
    const _itc = inst.getData().itemClass
    inst.update({title: {title: ' ', itemClass: 'animate-load color-fff'}, itemClass: _itc + ' flex-column-center-center'})
    setTimeout(() => {
      inst.reset()
    }, 1000);
  },
  onJump(e, params, inst) {
    const type = params.type
    wx.navigateTo({
      url: '../'+type+'/index'
    })
  },
  onClick(e, params, inst) {
    const type = params.type
    switch (type) {
      case '1':
        wx.showToast({title: '已发送', icon: 'success'})
        break;
      case '2':
        wx.showLoading({title: '加载中'})
        break;
    
      default:
        wx.showToast({title: '最长文案不超过20个字符', icon: 'none'})
        break;
    }
    setTimeout(() => {
      type == 1 ? wx.hideToast() : type == 2 ? wx.hideLoading() : ''
    }, 1000);
  },
  onShow: function () {},
  onReady: function () {
    const that = this
    this.$navbarLevel2 = this.getElementsById('navbarLevel2')
    this.viewPortHeight = wx.getSystemInfoSync().windowHeight
    this.toast = this.getElementsById('toast1')
    this.toast.update(mkModal({
      data: {
        title: '！！！SAUI旧版限时搬到另一个小程序',
        itemClass: 'ss-left'
      },
      close: true,
      closeCustom: {
        title: '查看',
        itemClass: '',
        aim: 'onJumpOther'
      },
      type: 'toast',
      actionSideWrapClass: 'bg-primary p-default size-form color-000'
    }))
  },
  onJumpOther() {
    wx.navigateToMiniProgram({
      appId: 'wx715dc8d465af1816',//小程序appid
      path: 'pages/index/index',//跳转关联小程序app.json配置里面的地址
      //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版） 
      envVersion: 'release',
      success(res) {
        console.log(res)
        // 打开成功
      }
    })
  },
  onLoad: function () {},
})
